import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_pro_01/components/shop_list.dart';

class MyApp21 extends StatefulWidget {
  const MyApp21({super.key});

  @override
  State<MyApp21> createState() => _MyApp21State();
}

class _MyApp21State extends State<MyApp21> {
  @override
  void initState() {
    super.initState();
    getData();
  }

  getData() async {
    Dio dio = Dio();
    final res = await dio.get('https://api-vue-base.itheima.net/api/joke');
    // https://mock.boxuegu.com/mock/1172/orders
    print(res.data);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // 背景颜色
      // backgroundColor: Colors.blueGrey,
      // 导航栏
      appBar: AppBar(
        // 导航栏标题
        title: Text('dio网络请求'),
        backgroundColor: const Color.fromARGB(255, 232, 221, 10),
      ),
      body: ListView.separated(
        itemBuilder: (BuildContext context, int index) {
          return ShopList();
        },
        // 便于划分割线
        separatorBuilder: (BuildContext context, int index) {
          return Divider(color: Colors.red, height: 1);
        },
        itemCount: 20,
      ),
    );
  }
}
